﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using myNico.Mode;
using System.IO.IsolatedStorage;
namespace myNico.Dao
{
   public class Dao_config
    {
       public static void SaveAsXmlFormat(Mode.config obj, string filename)
       {
           XmlSerializer xml = new XmlSerializer(typeof(config));
           using (Stream fs = new FileStream(filename,FileMode.Create))
           {
               xml.Serialize(fs, obj);
           }

       }

       public static config LoadFromXml(string filename)
       {
           config cf;
           XmlSerializer xm = new XmlSerializer(typeof(config));
           using (Stream fs =  File.OpenRead(filename))
           {
                cf =(config)xm.Deserialize(fs);
           }

           return cf;

         }


       public static void SaveAsIo(Mo_downPath mo, string filename)
       {
           IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
           IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename, FileMode.Create, isf);
           XmlSerializer xml = new XmlSerializer(typeof(Mo_downPath));


           xml.Serialize(stream, mo);
           stream.Close();
            
       }


       public static List<Mo_downPath> LoadFromIo(string filename)
       {
           List<Mo_downPath> mo;
           XmlSerializer xm = new XmlSerializer(typeof(Mo_downPath));
           IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
           IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filename,FileMode.Create,isf);
           mo = (List<Mo_downPath>)xm.Deserialize(stream);
           stream.Close();

           return mo;
       }
    }
}
